<template>
  <template v-if="list.length">
    <div class="sing-list">
      <lay-panel class="item" v-for="item in list" :key="item.id">
        <div class="flex">
          <!-- 点击播放歌曲 -->
          <div class="x-img">
            <div class="mask">
              <div class="svg-container">
                <svg-icon iconName="circlePlay" class="circlePlay hover" @click="addPlayList(item.id)"></svg-icon>
              </div>
            </div>
            <x-img class="haibao" :src="item.url"></x-img>
          </div>
          <!-- 点击进入详情 -->
          <div
            class="descrip ellipsis"
            @click="
              router.push({
                path: '/detail',
                query: {
                  type,
                  id: item.id
                }
              })
            "
          >
            <span class="hover-color">{{ item.description }}</span>
          </div>
        </div>
      </lay-panel>
    </div>
  </template>
  <lay-empty v-else></lay-empty>
</template>

<script setup>
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'
import {useStore} from 'vuex'
import * as axiosApi from './api'
defineProps({
  list: {
    type: [Array, Number],
    default() {
      return [
        // {
        //   id,
        //   url,
        //   description
        // }
      ]
    }
  },
  type: {
    type: [Number, String],
    default() {
      return 1
    }
  }
})
const router = useRouter()
const store = useStore()

function addPlayList(id){
  let parms={songlistNo:id}
  if(id.includes('GS')) parms={songerNo:id} 
  axiosApi.getSongsBySonglistNo(parms).then(res=>{
    store.commit('playList/REPLACE_PLAYLIST', res.data.content)
  })
}
</script>

<style lang="scss" scoped>
.sing-list {
  padding: 0 100px;
  display: flex;
  flex-wrap: wrap;
  .item {
    width: 19%;
    padding: 0 !important;
    border-radius: 5px;
    overflow: hidden;
    &:not(:nth-child(5n)) {
      margin-right: 10px;
    }
    .flex {
      display: flex;
      flex-direction: column;
      align-items: center;
      overflow: hidden;
      height: 150px;
      .descrip {
        box-sizing: border-box;
        padding: 5px;
        flex: 2.5;
        width: 100%;
        font-size: 13px;
      }
      .ellipsis {
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
      .x-img {
        position: relative;
        flex: 7.5;
        width: 100%;
        overflow: hidden;
        .circlePlay {
          display: none;
        }
        &:hover {
          .mask {
            display: none;
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 1;
            background-color: rgba(0, 0, 0, 0.25);
            .circlePlay {
              display: block;
              width: 50px;
              height: 50px;
              color: #fff;
              &:hover {
                color: $bar;
              }
            }
          }
        }
      }
    }
  }
}
</style>
